package com.jeasonzhao.report.engine.servlet.param;

import com.jeasonzhao.commons.utils.Algorithms;
import com.jeasonzhao.report.model.ReportParam;

public class TextBox extends AbstractSelector
{
    private static final String CSS_NAME = "sqlreport_parameter_text";
    private static final String Template = "<input"
        + " class=\"${class}\""
        + " type=\"text\""
        + " name=\"${controlId}\" id=\"${controlId}\""
        + " value=\"${dataValue}\""
        + " parameterName=\"${parameterName}\""
        + " dataType=\"${dataType}\""
        + " optional=\"${optional}\""
        + " ${appendInfo}"
        + "/>";
    public TextBox(ReportParam parameter)
    {
        super(parameter);
    }

    public String generate()
    {
        String strValueString = null;
        if(this.getParameter().hasBeenSetValues())
        {
            strValueString = Algorithms.toString(this.getParameter().getValue(0));
        }
        String className = CSS_NAME;
        String strAppendInfo = null;
        if(this.getParameter().getDataType().isDate())
        {
            className = CSS_NAME + " easyui-datebox";
            if(this.getParameter().isOptional() == false)
            {

            }
        }

        String controlScript = Algorithms.replaceStringByName(Template
            ,"controlId",this.getControlName()
            ,"dataValue",strValueString
            ,"parameterName",this.getParameter().getParam()
            ,"dataType",this.getParameter().getDataType().getConstantFieldName()
            ,"optional","" + this.getParameter().isOptional()
            ,"appendInfo",strAppendInfo
            ,"class",className);
        return controlScript;
    }
}
